home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 5.7 KB | 174 lines | [TEXT/ttxt] |
- --<<<-
- --*=============================================================================*
- --* Filename: tapetest.sx
- --*
- --* Other Files Required: interfac.sxl
- --*
- --* Purpose: Test the updated tape measure accessory. Run this to create the
- --* tapetest.sxt file. Then run that file to test the tape measure.
- --*
- --* Author: Robert Lockstone : 12-15-95
- --*=============================================================================*
-
- --*=============================================================================*
- --* Get the accessory interface module.
- --*=============================================================================*
- if ((getModule @AccessoryInterface) = false) do
- (
- open LibraryContainer dir:(parentDir theScriptDir) \
- path:"interfac.sxl"
- )
-
- module TapeTest
- uses ScriptX
- uses AccessoryInterface --Use the accessory interface defined in interfac.sxl
- end
-
- in module TapeTest
-
- class TapeTitle (TitleContainer)
- instance variables
- currentScene
- end
-
- method afterInit self {class TapeTitle} #rest args ->
- (
- apply nextMethod self args
-
- local w := new Window fill:whiteBrush
- w.name := "Tape Measure Test"
- w.title := self
-
- local str := "Use 'Open Accessory' from the File menu and look for tape.sxa."
- local txt := new TextPresenter boundary:(new Rect x2:400 y2:50) \
- target:str
- txt.position := new Point x:10 y:75
- prepend w txt
-
- self.name := "Tape Measure Test"
- self.currentScene := w
-
- append self.windows w
- )
-
- --*=============================================================================*
- --* Method to check if an accessory is appropriate for this title. It must
- --* answer the following questions:
- --*
- --* @question1 --Do you want to add yourself to me?
- --* @question2 --Do you inherit from TwoDPresenter, i.e. can you be appended
- --* to a window?
- --*=============================================================================*
- method isAppropriateAccessory self {class TapeTitle} acc ->
- (
- local answer := false
-
- if (isDefined accessoryAnswersGetter) and \
- (canObjectDo acc accessoryAnswersGetter) do
- (
- if ((getOne acc.accessoryAnswers @question1) = @yes) then
- (
- answer := true
- )
- else
- (
- if ((getOne acc.accessoryAnswers @question2) = @yes) do
- (
- answer := true
- )
- )
- )
-
- return answer
- )
-
- --*=============================================================================*
- --* Overridden method to get and add a generic accessory to a scene.
- --*
- --* (Note: This will not work for the tape measure accessory because the tape
- --* measure requires two items to be appended to the current scene, the
- --* tape measure and its 'display' instance variable. Also, the tape
- --* measure requires that the method updateScale be called on it after
- --* it has been appended to the current scene. But that is too specific
- --* for this general addAccessory method. That is why the tape measure
- --* takes care of adding itself to a title. See the tape measure
- --* accessory container's startupAction IV defined in maketape.sx.
- --*=============================================================================*
- method addAccessory self {class TapeTitle} acc ->
- (
- if ((getOne acc.accessoryAnswers @question1) != @yes) do
- (
- local thisAcc := (getAccessories acc)[1] --assume there is only one item
-
- --*======================================================================*
- --* You could put additional code in here to check the various
- --* answers in the accessoryAnswers IV of the AccessoryContainer,
- --* and decide what to do with the accessory based on those answers.
- --*
- --* I am going to get check to see if the accessory can do an addToTitle.
- --* If it can't, then I'll check to see if it's a presenter, and add it
- --* it myself.
- --*======================================================================*
-
- if (canObjectDo thisAcc addToTitle) then
- (
- addToTitle thisAcc pres:self.currentScene
- )
- else
- (
- if ((getOne acc.accessoryAnswers @question2) = @yes) do
- (
- prepend self.currentScene thisAcc
- )
- )
- )
-
- nextMethod self acc
- )
-
- -- Method importTool opens a file dialog to import the tape measure.
- -- (Note: stolen from AutoFinder.sx)
- method importTool self {class TapeTitle} ->
- (
- -- Open a file panel to import the tape measure.
- local op := new OpenPanel
- openFilePanel op
- if (not op.validReply) do return
-
- -- Open the storage container and load the tape meaure accessory.
- local fileName := op.filename[size op.fileName]
- deleteLast op.fileName
- local drep := spawn theRootDir op.fileName
- local c := open AccessoryContainer dir:drep path:fileName
- addAccessory self c
- )
-
- -- Method initKeyboardWatch sets up an event receiver for keyboard events,
- -- restricting the key code to the character "i". When an "i" is keyed and the
- -- @command key modifier is active, the importTool method is invoked on the
- -- stage manager.
- -- (Note: stolen from AutoFinder.sx)
- method initKeyboardWatch self {class TapeTitle} ->
- (
- local kd
- kd := new KeyboardDownEvent
- kd.device := new KeyboardDevice
- kd.eventReceiver := (arg interest ev ->
- if (isMember ev.keyModifiers @control) do importTool self)
- kd.maxKeyCode := 73
- kd.minKeyCode := 73
- addEventInterest kd
- )
-
- global tc := new TapeTitle dir:(parentDir theScriptDir) \
- path:"tapetest.sxt"
-
- tc.startupAction := (tc -> show tc.currentScene)
-
- append tc (getModule @TapeTest)
-
- close tc
-
- "Compiled tapetest.sx"
-
- -->>>